package demo5;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

public class ThreadDemo2 {
    public static int flag = 0;
    public static void main12(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
           while(flag == 0) {
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });

        Thread t2 = new Thread(()->{
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Scanner scanner = new Scanner(System.in);
            flag = scanner.nextInt();
        });

        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("ok");
    }


    public static void main(String[] args) {
        Deque<Integer> deque = new LinkedList<>();
        deque.push(12);
        deque.push(13);
        deque.push(14);
        deque.push(15);
        deque.push(16);



        System.out.println(deque.pollFirst());
        System.out.println(deque.pollLast());
        System.out.println(deque.getFirst());
        System.out.println(deque.getLast());
    }


}
class Parenthesis {
    public boolean chkParenthesis(String A, int n) {
        // write code here
        if (n % 2 != 0) {
            return false;
        }
        Deque<Character> deque = new LinkedList<>();
        for(int i = 0;i < n;i++) {
            char c = A.charAt(i);
            if(c != '(' && c != ')') {
                return false;
            } else {
                deque.push(c);
            }
        }

        while(!deque.isEmpty()) {
            char c1 = deque.pollFirst();
            char c2 = deque.pollLast();
            if(c1 == '(' && c2 == ')' ||
                    c1 == ')' && c2 == '(') {

            } else {
                return false;
            }
        }
        return true;
    }

//    public static void main(String[] args) {
//        Parenthesis parenthesis = new Parenthesis();
//        System.out.println(parenthesis.chkParenthesis("(()())", 6));
//    }

    public static int[] getFib() {
        int[] arr = new int[40];
        arr[0] = 0;
        arr[1] = 1;
        arr[2] = 1;
        int i = 3;
        while( i < 40 && arr[i] <= 1000000) {
            arr[i] = arr[i-1] + arr[i -2];
            i++;
        }
        return arr;
    }

    public static void main(String[] args) {
        int [] arr = getFib();
        System.out.println();
        String str = "asdf";
        System.out.println(str.compareTo("az"));


    }
}
class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {// 注意，如果输入是多个测试用例，请通过while循环处理多个测试用例
            int n = in.nextInt();
            String[] strs = new String[n];
            for (int i = 0;i < n;i++) {
                strs[i] = in.next();
            }
            boolean flag1 = isLengths(strs);
            boolean flag2 = isLexi(strs);
            if (flag1 && flag2) {
                System.out.println("both");
            } else if (flag1 && !flag2) {
                System.out.println("lengths");
            } else if (!flag1 && flag2) {
                System.out.println("lexicographically");
            } else {
                System.out.println("none");
            }
        }
    }

    public static boolean isLengths(String[] strs) {
        int[] arr = new int[strs.length];
        for(int i = 0;i < strs.length;i++) {
            arr[i] = strs[i].length();
        }
        for(int i = 0;i < arr.length - 1;i++) {
            if(arr[i] > arr[i+1]) {
                return false;
            }
        }
        return true;
    }
    public static boolean isLexi(String[] strs) {
        for(int i = 0; i < strs.length - 1;i++) {
            if(strs[i].compareTo(strs[i+1]) > 0) {
                return false;
            }
        }
        return true;
    }
}